/**
 * interface :定义接口
 * 
 * interface  接口名{  //首字母一定要大写
 *     属性1：数据类型，
 *     属性2：数据类型
 *     属性3：数据类型
 *     ....
 * }
 * */ 
//接口对json数据的约束
interface Product{
    title:string,
    price:number,
    num:number,
    ischecked:boolean,
    desc?:string,    //?  当前属性可有可无
    [propName:string]:any //添加无限个属性，而且值是任意类型
}

let list:Product[] = [
    {
        title:'香蕉',
        price:18,
        num:1,
        ischecked:true,
        shop:'每日优鲜',
        mark:'3点收'
    }
]

// let p2:Product = {
//     title:'苹果',
//     price:18,
//     num:1,
//     ischecked:true,
//     desc:'脆甜'
// }

// let p3:Product = {
//     title:'香蕉',
//     price:18,
//     num:1,
//     ischecked:true,
//     shop:'每日优鲜',
//     mark:'3点收'
// }


function add(product:Product){
    console.log(product.title)
}

add({
    title:'香蕉',
    price:18,
    num:1,
    ischecked:true,
    shop:'每日优鲜',
    mark:'3点收'
})

//接口对函数的约束

interface CompareInterface{
    (num1:number,num2:number):boolean
}

// function compareFun(num1:number,num2:number):boolean{
//     return num1>num2
// }

let compareFun:CompareInterface = (n1,n2) => {
    return n1>n2
}
compareFun(1,2)

//接口的继承  extends

interface Squear{
    width:number,
    height:number,
    long:number
}

interface Box extends Squear{
    color:string
}

let box:Box = {
    color:'red',
    width:12,
    height:10,
    long:10
}


//接口对类的约束   implements

//动物的接口
interface Animal{
    name:string,
    eat(thing:string):void
}

//狗
class Dog implements Animal{
    name:string;
    constructor(name:string){
        this.name = name
    }

    eat(thing:string){
        console.log(`${this.name}吃${thing}`)
    }
}

let taidi = new Dog('泰迪');

taidi.eat('狗粮');


//猫

class Cat implements Animal{
    name:string;
    constructor(name:string){
        this.name = name
    }

    eat(thing:string){
        console.log(`${this.name}吃${thing}`)
    }
}


let wumao = new Cat('无毛猫');

wumao.eat('鱼');

